package com.kucai.yifaqapp.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kucai.yifaqapp.R;
import com.kucai.yifaqapp.global.HttpAdress;
import com.kucai.yifaqapp.global.Info;
import com.kucai.yifaqapp.model.CustomObserver;
import com.kucai.yifaqapp.model.network.HttpJsonUtils;
import com.kucai.yifaqapp.model.network.entity.res.z_user_MsgBean;
import com.kucai.yifaqapp.util.SYSOUtils;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class UserActivity extends BaseActivitySimple {
    private TextView user1;
    private TextView user2;
    private TextView user3;
    private TextView user4;
    private TextView user5;
    private RelativeLayout back;
    private LinearLayout skinbg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);
        user1 = findViewById(R.id.user1);
        user2 = findViewById(R.id.user2);
        user3 = findViewById(R.id.user3);
        user4 = findViewById(R.id.user4);
        user5 = findViewById(R.id.user5);
        skinbg = findViewById(R.id.skinbg);
        back = findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        initData();
    }

    private void initData() {
        HttpJsonUtils.getHttpApiInstance()
                .get_user_msg(HttpAdress.getuseAdress() + "api/m/user/getUserMsg",Info.user.token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<z_user_MsgBean>(this) {
                    @Override
                    protected void onCustomNext(z_user_MsgBean resBanner) {
                        try {
                            user1.setText(resBanner.getUsername() + "");
                            user2.setText("用户余额：" + resBanner.getBalance());
                            user3.setText(resBanner.getUsername() + "");
                            user4.setText(resBanner.getFullName() + "");
                            user5.setText(resBanner.getCurrency() + "");
                        } catch (Exception e) {

                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                        SYSOUtils.sOut(e.toString());
                    }
                });
    }

    @Override
    protected int setContentView() {
        return R.layout.activity_user;
    }

    @Override
    protected void ChangeSkin() {
        switch (SkinId) {
            case 17771:
                skinbg.setBackgroundResource(R.mipmap.skin_bg1);
                break;
            case 17772:
                skinbg.setBackgroundResource(R.mipmap.skin_bg2);
                break;
            case 17773:
                skinbg.setBackgroundResource(R.mipmap.skin_bg3);
                break;
            default:
                skinbg.setBackgroundResource(R.mipmap.skin_bg1);
        }
    }
}
